package com.atguigu.springcloud.controller;

import com.atguigu.springcloud.entities.CommonResult;
import com.atguigu.springcloud.entities.Payment;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import javax.annotation.Resource;

@RestController
@Slf4j
public class OrderController {
    //private static final String PAYMENT_URL = "http://localhost:8001/api/payment";
    private static final String PAYMENT_URL = "http://CLOUD-PROVIDER-PAYMENT";
    @Resource
    private RestTemplate restTemplate;

    @GetMapping(value = "/getById")
    public CommonResult getById(Long id){
        return restTemplate.getForObject(PAYMENT_URL+"/getById?id="+id,CommonResult.class);
    }

    @PostMapping(value = "/add")
    public CommonResult add(@RequestBody Payment payment){
        return restTemplate.postForObject(PAYMENT_URL+"add",payment,CommonResult.class);
    }

}
